From 999894e11ecfc806d3bb470a9e90c18d76e86f27 Mon Sep 17 00:00:00 2001 From: robertl Date: Fri, 30 Jun 2006 04:41:15 +0000 Subject: [PATCH] Generalize the "comX, X>=10" fix for all the Windows code. Let the Magellan track reader NOT merge tracks across files. Magellan track reader names tracks after file read. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@2180 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/defs.h | 7 ++++ gpsbabel/gbser.h | 4 +++ gpsbabel/gbser_win.c | 50 ++++++++++++++++++++++++----- gpsbabel/jeeps/gpsserial.c | 5 +-- gpsbabel/magproto.c | 31 +++++++++++++++--- gpsbabel/reference/track/tracks.gpx | 1 + 6 files changed, 84 insertions(+), 14 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index e7b23d481..7987a6b3a 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -76,6 +76,13 @@ # define _CRT_SECURE_NO_DEPRECATE 1 #endif +/* Pathname separator character */ +#if __WIN32__ +# define GB_PATHSEP '\\' +#else +# define GB_PATHSEP '/' +#endif + /* * Toss in some GNU C-specific voodoo for checking. */ diff --git a/gpsbabel/gbser.h b/gpsbabel/gbser.h index ea6be83eb..44cf3f787 100644 --- a/gpsbabel/gbser.h +++ b/gpsbabel/gbser.h @@ -23,3 +23,7 @@ void *gbser_init(const char *name); void gbser_deinit (void *); int gbser_read(void *handle, char *ibuf, int sz); int gbser_setspeed(void *handle, unsigned speed); + +#if __WIN32__ +char * fix_win_serial_name(const char *comname); +#endif diff --git a/gpsbabel/gbser_win.c b/gpsbabel/gbser_win.c index b26db2c99..c113614ff 100644 --- a/gpsbabel/gbser_win.c +++ b/gpsbabel/gbser_win.c @@ -36,16 +36,17 @@ gbser_init(const char *portname) // DCB tio; COMMTIMEOUTS timeout; HANDLE comport; - char *xname= xstrdup("\\\\.\\\\"); +// char *xname= xstrdup("\\\\.\\\\"); + char *xname = fix_win_serial_name(portname); gbser_win_handle* handle = xcalloc(1, sizeof(*handle));; - /* Amazingly, windows will fail the open below unless we - * prepend \\.\ to the name. It also then fails the open - * unless we strip the colon from the name. Aaaaargh! - */ - xname = xstrappend(xname, portname); - if (xname[strlen(xname)-1] == ':') - xname[strlen(xname)-1] = 0; +// /* Amazingly, windows will fail the open below unless we +// * prepend \\.\ to the name. It also then fails the open +// * unless we strip the colon from the name. Aaaaargh! +// */ +// xname = xstrappend(xname, portname); +// if (xname[strlen(xname)-1] == ':') +// xname[strlen(xname)-1] = 0; // xCloseHandle(comport); comport = CreateFile(xname, GENERIC_READ|GENERIC_WRITE, @@ -176,3 +177,36 @@ gbser_deinit(void *handle) gbser_win_handle *h = (gbser_win_handle *) handle; xfree(h); } + + + + +/* + * This isn't part of the above abstraction; it's just a helper for + * the other serial modules in the tree. + * + * Windows does a weird thing with serial ports. + * COM ports 1 - 9 are "COM1:" through "COM9:" + * The one after that is \\.\\com10 - this function tries to plaster over + * that. + * It returns a pointer to a staticly allocated buffer and is therefore not + * thread safe. The buffer pointed to remains valid only until the next + * call to this function. + */ +static char gb_com_buffer[100]; + +char * +fix_win_serial_name(const char *comname) +{ + /* If in the form 'COMx:', use it in place */ + if ((strlen(comname) == 5) && (comname[4] == ':')) { + strcpy(gb_com_buffer, comname); + } else { + snprintf(gb_com_buffer, sizeof(gb_com_buffer), + "\\\\.\\\\%s", comname); + if (gb_com_buffer[strlen(gb_com_buffer) - 1 ] == ':') { + gb_com_buffer[strlen(gb_com_buffer) - 1] = 0; + } + } + return gb_com_buffer; +} diff --git a/gpsbabel/jeeps/gpsserial.c b/gpsbabel/jeeps/gpsserial.c index 543766dd2..53dc1e62c 100644 --- a/gpsbabel/jeeps/gpsserial.c +++ b/gpsbabel/jeeps/gpsserial.c @@ -88,14 +88,15 @@ int32 GPS_Serial_On(const char *port, gpsdevh **dh) DCB tio; COMMTIMEOUTS timeout; HANDLE comport; + char *xname = fix_win_serial_name(port); win_serial_data *wsd = xcalloc(sizeof (win_serial_data), 1); *dh = (gpsdevh*) wsd; - comport = CreateFile(port, GENERIC_READ|GENERIC_WRITE, 0, NULL, + comport = CreateFile(xname, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (comport == INVALID_HANDLE_VALUE) { - GPS_Serial_Error("CreateFile on '%s' failed", port); + GPS_Serial_Error("CreateFile on '%s' failed", xname); gps_errno = SERIAL_ERROR; return 0; } diff --git a/gpsbabel/magproto.c b/gpsbabel/magproto.c index b21365558..1c5e6a317 100644 --- a/gpsbabel/magproto.c +++ b/gpsbabel/magproto.c @@ -48,6 +48,7 @@ static char *nukewpt = NULL; static int route_out_count; static int waypoint_read_count; static int wpt_len = 8; +static const char *curfname; typedef enum { mrs_handoff = 0, @@ -467,6 +468,24 @@ retry: */ if (trk_head == NULL) { trk_head = route_head_alloc(); + /* These tracks don't have names, so derive one + * from input filename. + */ + const char *s = strrchr(curfname, GB_PATHSEP); + char *e; + if (s) { + s++; /* Skip path delim */ + } else { + s = curfname;/* use name intact */ + } + + /* Whack trailing extension if present. */ + trk_head->rte_name = xstrdup(s); + e = strrchr(trk_head->rte_name, '.'); + if (e) { + *e = '\0'; + } + track_add_head(trk_head); } @@ -525,14 +544,15 @@ int terminit(const char *portname, int create_ok) { DCB tio; - char *xname = xstrdup("\\\\.\\\\"); +// char *xname = xstrdup("\\\\.\\\\"); + char *xname = fix_win_serial_name(portname); COMMTIMEOUTS timeout; is_file = 0; - xname = xstrappend(xname, portname); - if (xname[strlen(xname)-1] == ':') - xname[strlen(xname)-1] = 0; +// xname = xstrappend(xname, portname); +// if (xname[strlen(xname)-1] == ':') +// xname[strlen(xname)-1] = 0; xCloseHandle(comport); @@ -751,6 +771,7 @@ mag_rd_init_common(const char *portname) { time_t now, later; waypoint_read_count = 0; + curfname = portname; if (bs) { bitrate=atoi(bs); @@ -908,6 +929,8 @@ mag_deinit(void) mkshort_del_handle(&mkshort_handle); waypt_flush(&rte_wpt_tmp); + + trk_head = NULL; } diff --git a/gpsbabel/reference/track/tracks.gpx b/gpsbabel/reference/track/tracks.gpx index c606cd414..55dd18771 100644 --- a/gpsbabel/reference/track/tracks.gpx +++ b/gpsbabel/reference/track/tracks.gpx @@ -7,6 +7,7 @@ xmlns="http://www.topografix.com/GPX/1/0" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"> +meridian 1.000000 -- 2.30.2